const { defineConfig } = require('@vue/cli-service')
const { IgnorePlugin } = require('webpack')

const path = require('path');

function resolve (dir) {
  return path.join(__dirname, dir);
}

module.exports = defineConfig({
  publicPath: './',
  productionSourceMap:false,
  transpileDependencies: true,
  lintOnSave: false,
  pluginOptions: {
    plugins: [
      new IgnorePlugin({
        resourceRegExp: /serialport/
      })
    ],
    electronBuilder: {
      customFileProtocol: "./",
      nodeIntegration: true,
      builderOptions:{
        asar: false,
        productName: "safehat",
        win: {
          target: [
              "nsis",
              "zip"
          ]
        }
      },
      externals: [
        'serialport'
      ]
    }
  },
  chainWebpack: config => {
    config.resolve.alias
        .set('@', resolve('src'))
        .set('src', resolve('src'))
        .set('common', resolve('src/common'))
        .set('components', resolve('src/components'))
        .set('static', resolve(__dirname, 'public'))
    config.module
        .rule('vue')
        .use('vue-loader')
        .loader('vue-loader')
        .tap((options) => {
            options.compilerOptions = {
            ...(options.compilerOptions || {}),
            isCustomElement: (tag) => /^webview/.test(tag)
            }
            return options
        })
  }
})
